package com.token.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.token.common.ResultMessage;
import com.token.model.dto.SysUserDTO;
import com.token.model.vo.TestDictDataUserVO;
import com.token.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @auther: henriy
 * @Date: 2023/10/25
 */
@Api(tags = "用户接口类")
@RestController
@RequestMapping("/user/info")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/login")
    @ApiOperation("登录")
    public ResultMessage login(@Validated @RequestBody SysUserDTO sysUserDTO, HttpServletRequest request) throws Exception {
        return ResultMessage.isOk(userService.login(sysUserDTO, request));
    }

    @GetMapping("/logout")
    @ApiOperation("退出")
    public ResultMessage logout() {
        StpUtil.logout();
        return ResultMessage.isOk();
    }

    @GetMapping("/page")
    public ResultMessage<IPage<TestDictDataUserVO>> page() {
        return ResultMessage.isOk(userService.page());
    }

}
